package cn.wolfcode.trip.api.controller;

import cn.wolfcode.trip.base.domain.Comment;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.service.ICommentService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/comments")
public class CommentController {
    @Autowired
    private ICommentService commentService;

    /**
     * 查询我的评论
     */
    @GetMapping("/list/{userId}")
    public PageInfo<Comment> list(CommentQueryObject qo) {
        qo.setOrderBy("c.commentTime desc");
        PageInfo<Comment> pageInfo = commentService.query(qo);
        return pageInfo;
    }

    /**
     * 保存评论
     *1.资源   /comments
     *2.请求方式   POST
     *3.请求参数   Map
     *4.返回结果   JsonResult
     */
    @PostMapping
    public JsonResult saveComment(Comment comment){
        commentService.save(comment);
        return new JsonResult();
    }

    /**
     * 查询对应的评论内容
     *1.资源   /comments
     *2.请求方式   get
     *3.请求参数   modelState, articleId
     *4.返回结果   List<Comment>
     */
    @GetMapping("/{articleId}/{modelState}")
    public PageInfo<Comment> listComment(CommentQueryObject qo){
        qo.setOrderBy("commentTime desc");
        return commentService.query(qo);
    }

    /**
     * 点评头条
     * 1.资源:/comments/HotCommentList
     * 2.请求方式:get
     * 3.请求参数:无
     * 4.返回结果:List<Comment>
     */
    @GetMapping("/HotCommentList")
    public List<Comment> HotCommentList(){
        return commentService.HotCommentList();
    }



}
